/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Entidades;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 *
 * @author ivana
 */
@Entity
@Table(name = "operariorol")
@NamedQueries({
    @NamedQuery(name = "Operariorol.findAll", query = "SELECT o FROM Operariorol o"),
    @NamedQuery(name = "Operariorol.findByIdoperariorol", query = "SELECT o FROM Operariorol o WHERE o.idoperariorol = :idoperariorol"),
    @NamedQuery(name = "Operariorol.findByIdoperario", query = "SELECT o FROM Operariorol o JOIN o.operario c WHERE c.idoperario = :idoperario and (o.fechafin is null or o.fechafin ='')"),
    @NamedQuery(name = "Operariorol.findByFechainicio", query = "SELECT o FROM Operariorol o WHERE o.fechainicio = :fechainicio"),
    @NamedQuery(name = "Operariorol.findACR", query = "SELECT d FROM Operariorol d  WHERE  d.area = :area AND d.cargo = :cargo AND d.rol=:rol AND d.operario = :operario"),
     @NamedQuery(name = "Operariorol.findAR", query = "SELECT d FROM Operariorol d  WHERE  d.area = :area  AND d.rol=:rol AND d.operario = :operario"),
    @NamedQuery(name = "Operariorol.findByFechafin", query = "SELECT o FROM Operariorol o WHERE o.fechafin = :fechafin")})
public class Operariorol implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idoperariorol")
    private Integer idoperariorol;
    @Basic(optional = false)
    @Column(name = "fechainicio")
    private String fechainicio;
    @Column(name = "fechafin")
    private String fechafin;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "operariorol")
    private Collection<Usuario> usuarioCollection;
    @JoinColumn(name = "idarea", referencedColumnName = "idArea")
    @ManyToOne(optional = false)
    private Area area;
    @JoinColumn(name = "idcargo", referencedColumnName = "idCargo")
    @ManyToOne(optional = false)
    private Cargo cargo;
    @JoinColumn(name = "idrol", referencedColumnName = "idRol")
    @ManyToOne(optional = false)
    private Rol rol;
    @JoinColumn(name = "idoperario", referencedColumnName = "idoperario")
    @ManyToOne(optional = false)
    private Operario operario;

    public Operariorol() {
    }

    public Operariorol(Integer idoperariorol) {
        this.idoperariorol = idoperariorol;
    }

    public Operariorol(Integer idoperariorol, String fechainicio) {
        this.idoperariorol = idoperariorol;
        this.fechainicio = fechainicio;
    }

    public Integer getIdoperariorol() {
        return idoperariorol;
    }

    public void setIdoperariorol(Integer idoperariorol) {
        Integer oldIdoperariorol = this.idoperariorol;
        this.idoperariorol = idoperariorol;
        changeSupport.firePropertyChange("idoperariorol", oldIdoperariorol, idoperariorol);
    }

    public String getFechainicio() {
        return fechainicio;
    }

    public void setFechainicio(String fechainicio) {
        String oldFechainicio = this.fechainicio;
        this.fechainicio = fechainicio;
        changeSupport.firePropertyChange("fechainicio", oldFechainicio, fechainicio);
    }

    public String getFechafin() {
        return fechafin;
    }

    public void setFechafin(String fechafin) {
        String oldFechafin = this.fechafin;
        this.fechafin = fechafin;
        changeSupport.firePropertyChange("fechafin", oldFechafin, fechafin);
    }

    public Collection<Usuario> getUsuarioCollection() {
        return usuarioCollection;
    }

    public void setUsuarioCollection(Collection<Usuario> usuarioCollection) {
        this.usuarioCollection = usuarioCollection;
    }

    public Area getArea() {
        return area;
    }

    public void setArea(Area area) {
        Area oldArea = this.area;
        this.area = area;
        changeSupport.firePropertyChange("area", oldArea, area);
    }

    public Cargo getCargo() {
        return cargo;
    }

    public void setCargo(Cargo cargo) {
        Cargo oldCargo = this.cargo;
        this.cargo = cargo;
        changeSupport.firePropertyChange("cargo", oldCargo, cargo);
    }

    public Rol getRol() {
        return rol;
    }

    public void setRol(Rol rol) {
        Rol oldRol = this.rol;
        this.rol = rol;
        changeSupport.firePropertyChange("rol", oldRol, rol);
    }

    public Operario getOperario() {
        return (Operario) operario;
    }

    public void setOperario(Operario operario) {
        this.operario = (Operario)  operario;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idoperariorol != null ? idoperariorol.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Operariorol)) {
            return false;
        }
        Operariorol other = (Operariorol) object;
        if ((this.idoperariorol == null && other.idoperariorol != null) || (this.idoperariorol != null && !this.idoperariorol.equals(other.idoperariorol))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entidades.Operariorol[idoperariorol=" + idoperariorol + "]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }

}
